﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace WindowsEventLogManager
{
    public class EventSourceInfo
    {
        #region Constructors

        public EventSourceInfo(EventLogInfo parent, string name)
        {
            this.Parent = parent;
            this.Name = name;
        }

        #endregion

        #region Properties

        public EventLogInfo Parent
        {
            get;
            private set;
        }

        public string Name
        {
            get;
            private set;
        }

        #endregion

        #region Methods

        public void Delete()
        {
            string[] values = this.Parent.RegistryKey.GetValue("Sources") as string[];

            IEnumerable<string> newValues = values.Where(r => r != this.Name);

            this.Parent.RegistryKey.SetValue("Sources", newValues.ToArray(), Microsoft.Win32.RegistryValueKind.MultiString);

            this.Parent.Sources.Remove(this);
        }

        public override string ToString()
        {
            return this.Name;
        }

        #endregion
    }
}
